home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 9 / 009.d81 / dos #21 < prev    next >
Text File  |  2022-08-26  |  2KB  |  139 lines

  1.  
  2.       DOS and DON'TS  -- PART 21
  3.       ==========================
  4.  
  5.            by Jimmy Weiler
  6.  
  7.  
  8.  
  9.   The command to open a RELative file
  10.  
  11. is similar to that used for a SEQ file
  12.  
  13.  
  14.  
  15.   OPEN <file number>,<device number>,
  16.    <channel number>,<file name>",L,"
  17.    CHR$(<record length>)
  18.  
  19.  
  20.  
  21.   That's a bit overwhelming so lets
  22.  
  23. simplify it with an example and then
  24.  
  25. cover it a piece at a time.
  26.  
  27.  
  28.  
  29. OPEN 3,8,4,"PHONEFILE,L,"+CHR$(89)
  30.  
  31.  
  32.  
  33.   "OPEN" tells DOS to prepare to use
  34.  
  35. the file.   The file will be number
  36.  
  37. "3", so any PRINT# or INPUT# or GET#
  38.  
  39. statements intended for that file will
  40.  
  41. have to use #3.  The device number is
  42.  
  43. "8" -- that's just the disk unit
  44.  
  45. number.  For most of us it is always
  46.  
  47. 8.  "4" is the channel number.  That
  48.  
  49. tells DOS which pathway to take to get
  50.  
  51. to the disk.  You will have to use the
  52.  
  53. channel number again and again as you
  54.  
  55. access a relative file.   "PHONEFILE"
  56.  
  57. is the name of the relative file.  It
  58.  
  59. will appear in the disk directory,
  60.  
  61. followed by ":REL".
  62.  
  63.   Up to this point, the syntax has
  64.  
  65. been the same as for a SEQuential type
  66.  
  67. file.  The last part of a RELative
  68.  
  69. file open statement is the only
  70.  
  71. distinction.  The "L" or length
  72.  
  73. parameter tells DOS how many
  74.  
  75. characters each record of the REL
  76.  
  77. file will hold.
  78.  
  79.   In our example, ",L,"+CHR$(89)
  80.  
  81. establishes each record as 89
  82.  
  83. characters long.  The reason I
  84.  
  85. chose 89 is that INPUT# will accept
  86.  
  87. inputs up to 88 characters in length
  88.  
  89. from a disk file.  The extra character
  90.  
  91. is for the carriage return that will
  92.  
  93. mark the end of input when we read
  94.  
  95. the file.  You can use any record
  96.  
  97. length from 1 to 254 characters,
  98.  
  99. except 58 -- 58 produces a syntax
  100.  
  101. error.  (More on this oddity later.)
  102.  
  103.   When you create REL files, you need
  104.  
  105. to know the maximum amount of data
  106.  
  107. that will ever be written to a record
  108.  
  109. and the number of "fields" each record
  110.  
  111. will have.  Let's say we were making
  112.  
  113. a file of the last name and phone
  114.  
  115. number of everybody in our class at
  116.  
  117. school.  All their phone numbers are
  118.  
  119. seven digits long, so that's no
  120.  
  121. problem, but the names will vary in
  122.  
  123. length.  We have to take the longest
  124.  
  125. name we expect to find and make room
  126.  
  127. for that in each record.
  128.  
  129.   It turns out that Joe Schlabotnik
  130.  
  131. has the longest name in my class, so
  132.  
  133. I have to allow 11 characters for the
  134.  
  135. "name field" in each record.
  136.  
  137.  
  138. ------- Continued in Part 22 ---------
  139.